#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using i128 = __int128;
const int N = 1e5 + 5;

int a[N];
int s[35][N];

void solve() {
    int l, r;
    ll cnt = 0;
    cin >> l >> r;
    for (int j = 0; j < 31; j++) {
        int d = s[j][r] - s[j][l - 1];
        int len = r - l + 1;
        if (d < len - d) cnt += 1 << j;
    }
    cout << cnt << endl;
    return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        for (int j = 0; j <= 30; j++) {
            s[j][i] = s[j][i - 1] + ((a[i] >> j) & 1);
        }
    }
    int q;
    cin >> q;
    while (q--) solve();

    return 0;
}